package com.bingyuan.aipassproject.utils;

import android.content.Context;
import android.os.Build;

import com.yanzhenjie.permission.AndPermission;

public class PermissionUtils {
    /**
     * 注释：权限申请回调
     */
    public interface PermissionListener {
        void onSuccess(Context context);

        void onFailed(Context context);
    }

    /**
     * 注释：应用相关组权限
     */
    public static void applicationPermissions(Context context, PermissionListener listener, String[]... permissions) {
        if (!AndPermission.hasPermissions(context, permissions)) {
            AndPermission.with(context)
                    .runtime()
                    .permission(permissions)
                    .rationale((mContext, data, executor) -> {
                        //选择显示提示弹窗
                        executor.execute();
                    })
                    .onGranted((permission) -> {
                        listener.onSuccess(context);
                    })
                    .onDenied((permission) -> {
                        listener.onFailed(context);
                    })
                    .start();
        } else {
            listener.onSuccess(context);
        }
    }

}
